import numpy as np
import os

np.set_printoptions(precision=3, suppress=True)

mean_list = []
std_list = []
def mean_std(root_path = '1'):
    solved_number = 0
    all_episodes = []
    for file in os.listdir(root_path):
        file_path = os.path.join(root_path, file)
        content = open(file_path).readlines()
        #print("第", file[:-4], "个文件。", content[-2], end='')
        if "Task solved" in content[-2]:
            solved_number+=1
            all_episodes.append(int(content[-2].split()[3]))
    mean_list.append(np.mean(all_episodes))
    std_list.append(np.std(all_episodes))
    print("mean:%13.4f"%np.mean(all_episodes), "      std:%13.4f"%np.std(all_episodes), "共解决任务数: %3d"%solved_number)
    
for root_path in [5, 20]:
    print("batch_size 为：%5d"%root_path, end=" "*5)
    mean_std(str(root_path))

a = np.array(mean_list)[1]/np.array(mean_list)[0]
b = np.array([5, 20])[1:]/np.array([5, 20])[:-1]
print('后一种batch_size设置对前一种设置的运算效率(特指网络更新步骤)提升：')
print(b/a)

"""
c = np.array(mean_list)[1:]/np.array(mean_list)[0]
d = np.array([5, 20])[1:]/np.array([1])
print('后一种batch_size设置对第一种设置的运算效率(特指网络更新步骤)提升：')
print(d/c)
"""
